#include "timewheel.hpp"

class test
{
public:
    test()
    {
        std::cout << "test()" << std::endl;
    }
    ~test()
    {
        std::cout << "~test()" << std::endl;
    }
};

void deltask(test *t)
{
    std::cout << "void deltask(test *t)" << std::endl;
    delete t;
}

int main()
{
    zj::TimeWheel timewheel;
    test *t = new test();
    func_t f = std::bind(deltask, t);

    timewheel.addTimer(888, f, 2); // 这里的5意味着会放在定时器的下标为5的地方
    for (int i = 0; i < 5; i++)
    {
        sleep(1);
        timewheel.TimerRefresh(888); // 刷新定时任务
        timewheel.RunTimerTask();    // 向后移动秒针
        std::cout << "刷新了一下定时任务,重新需要2s中后才会销毁\n";
    }
    while (1)
    {
        sleep(1);
        std::cout << "-------------------\n";
        timewheel.RunTimerTask(); // 向后移动秒针
    }

    return 0;
}
